package amqp

import (
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gctx"
	"github.com/streadway/amqp"
)

var MQ *amqp.Connection

// RabbitMQ 链接
func RabbitMQ() {
	var ctx = gctx.New()
	// RabbitMQ分配的用户名称
	var user, _  = g.Cfg().Get(ctx, "rabbitMq.user")
	// RabbitMQ用户的密码
	var pwd, _  = g.Cfg().Get(ctx, "rabbitMq.pwd")
	// RabbitMQ Broker 的ip地址
	var host, _  = g.Cfg().Get(ctx, "rabbitMq.host")
	// RabbitMQ Broker 监听的端口
	var port, _  = g.Cfg().Get(ctx, "rabbitMq.port")
	url := "amqp://"+user.String()+":"+pwd.String()+"@"+host.String()+":"+port.String()+"/my_vhost"
	conn, err := amqp.Dial(url)
	if err != nil {
		panic(err)
	}
	MQ = conn
}
